package com.pan.action.chain.impl;

import com.pan.domain.invariability.GlobalInformation;
import com.pan.action.chain.ChainAction;
import com.pan.show.record.Record;
import com.pan.utils.ApplicationConfig;
import com.pan.utils.MyMouseInfo;
import com.pan.utils.ShortcutKeyConfig;

import javax.swing.*;
import java.awt.*;
import java.util.Set;

public class ResetOriginAction extends ChainAction<Set<String>> {

    private String[] targetKeys;

    {
        String shortcutKey = ShortcutKeyConfig.INSTANCE.getOriginKey();
        targetKeys = shortcutKey.trim().split("\\+");
    }

    public ResetOriginAction() {
    }

    @Override
    public void handle(Set<String> keys) {
        for (String k:targetKeys){
            if (!keys.contains(k)) return;
        }
        Point point = MyMouseInfo.INSTANCE.getPoint();//MouseInfo.getPointerInfo().getLocation();
        int x = (int) point.getX();
        int y = (int) point.getY();;
        GlobalInformation.setOriginXY(x,y);
        String tipsStr = "Setting origin position succeeded!\n";
        tipsStr += GlobalInformation.getOriginXYString()+"\n";

        //show
        Record record = ApplicationConfig.INSTANCE.getRecordFactory().getRecord();
        record.setContent(tipsStr);
        record.display();
//        JFrame tipsFrame = new JFrame("tips");
//        tipsFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
//        JLabel tipLabel = new JLabel(tipsStr);
//        tipsFrame.add(tipLabel);
//        tipsFrame.setVisible(true);
    }
}
